#include "ConsoleColor.h"

#include <Windows.h>

namespace COLOR
{
	ostream& operator<<(ostream& out, Color c)
	{
		CONSOLE_SCREEN_BUFFER_INFO csbinfo;

		HANDLE hConsole;
		hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
		GetConsoleScreenBufferInfo(hConsole, &csbinfo);
		WORD oldinfo = csbinfo.wAttributes;

		WORD bgColor = oldinfo >> 4;
		WORD largeBgColor = bgColor << 4;

		WORD textColor = oldinfo - largeBgColor;

		if( c > WHITE )
			bgColor = c;
		else
			textColor = c;

		SetConsoleTextAttribute(hConsole, textColor+(bgColor*16));

		return out;
	}
}